package com.gtw.state;

public class Context {

    /**
     * 1.定义状态(状态为静态常量)
     */
    public final static State STATE1 = new ConcreteState1();
    public final static State STATE2 = new ConcreteState2();

    /**
     * 当前状态
     */
    private State currentState;

    /**
     * 2.行为委托,具有状态抽象角色定义的所有行为,具体执行使用委托
     */

    public void doSomething(int type){

    }
    public void handle1() {
        this.currentState.handle1();
    }

    public void handle2() {
        this.currentState.handle2();
    }

    public State getCurrentState() {
        return currentState;
    }

    public void setCurrentState(State currentState) {
        this.currentState = currentState;
        //切换状态
        this.currentState.setContext(this);
    }
}
